/**
 * @author 徐楠
 * @date 2022/5/3 15:40
 * @version 1.0
 */

package com.xunan.likou;

public class OptimalDivision {
    public static void main(String[] args) {
        int[] nums = {1000, 100, 10, 2};
        String s = optimalDivision(nums);
        System.out.println(s);
    }

    /**
     * 求 a/b/c/d/e/...最大，即分母最小，分子最大。
     * 故 max = a/(b/c/d/e/...)  让分母一直除就能变得最小
     */
    public static String optimalDivision(int[] nums) {
        if (nums.length == 1) {
            return nums[0] + "";
        } else if (nums.length == 2) {
            return nums[0] + "/" + nums[1];
        }
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(nums[0]);
        stringBuilder.append("/(");
        for (int i = 1; i < nums.length; i++) {
            stringBuilder.append(nums[i]);
            if (i != nums.length - 1) {
                stringBuilder.append("/");
            }
        }
        stringBuilder.append(")");
        return stringBuilder.toString();
    }
}
